//package me.zhengjie.minbearwcs.serivce.agv;
//
//import lombok.RequiredArgsConstructor;
//import me.zhengjie.observer.caster.WcsMulticaster;
//import me.zhengjie.observer.event.DefaultEvent;
//import me.zhengjie.observer.type.agv.AgvActionEventType;
//import me.zhengjie.observer.type.agv.AgvTaskEventType;
//import org.springframework.stereotype.Service;
//import org.springframework.transaction.annotation.Transactional;
//import me.zhengjie.minbearwcs.dao.agv.inf.AgvMissionDao;
//import me.zhengjie.minbearwcs.dao.agv.inf.AgvMissionDetailDao;
//import me.zhengjie.minbearwcs.dao.storage.inf.DualHeadStorageDao;
//import me.zhengjie.minbearwcs.entity.DTO.agv.TUSK.TUSKFeedBackTask;
//import me.zhengjie.minbearwcs.entity.DTO.agv.event.TUSKFeedBackEvent;
//import me.zhengjie.minbearwcs.entity.DTO.agv.task.actionEnum.AgvAction;
//import me.zhengjie.minbearwcs.entity.PO.agv.AgvMission;
//import me.zhengjie.minbearwcs.entity.PO.agv.AgvMissionDetail;
//import me.zhengjie.minbearwcs.serivce.mission.storageProcessor.booking.Floor3Or4.Storage3Or4FloorBookingSelector;
//import me.zhengjie.minbearwcs.serivce.mission.storageProcessor.locker.Floor3Or4.Storage3Or4FloorLocker;
//
//@Service
//@RequiredArgsConstructor
//public class AgvService {
//
//    private final AgvMissionDao agvMissionDao;
//    private final AgvMissionDetailDao agvMissionDetailDao;
//    private final Storage3Or4FloorLocker storage3Or4FloorLocker;
//    private final Storage3Or4FloorBookingSelector storage3Or4FloorBookingSelector;
//    private final DualHeadStorageDao dualHeadStorageDao;
//
//    private final WcsMulticaster wcsMulticaster;
//
//    @Transactional
//    public boolean feedbackTask(TUSKFeedBackTask tuskFeedBackTask) {
//        String taskId = tuskFeedBackTask.getTaskId();
//        String targetPoint = tuskFeedBackTask.getTargetPoint();
//        // 1.找出任务类型和点位
//        AgvMission agvMission = agvMissionDao.selectByTaskId(taskId);
//        AgvMissionDetail agvMissionDetail = agvMissionDetailDao.selectByTaskIdAndPoint(taskId, targetPoint);
//        TUSKFeedBackEvent feedBackEvent = new TUSKFeedBackEvent(agvMission, agvMissionDetail, tuskFeedBackTask);
//
//        // 2.释放储位
//        decideActionEvent(feedBackEvent);
//
//        // 3.修改agv任务的信息
////        updateMissionInfo(agvMission, agvMissionDetail, tuskFeedBackTask.getAgvNo());
//
//        // 4.发布agv任务状态变更事件
//        return false;
//    }
//
//
//    private void decideActionEvent(TUSKFeedBackEvent feedBackEvent){
//        AgvMissionDetail agvMissionDetail = feedBackEvent.getAgvMissionDetail();
//        AgvAction agvAction = AgvAction.valueOf(agvMissionDetail.getAction());
//
//        DefaultEvent defaultEvent = DefaultEvent.create(feedBackEvent);
//        switch (agvAction){
//            case GET:
//                wcsMulticaster.multicastEvent(defaultEvent, AgvActionEventType.GET);
//                break;
//            case PASS:
//                wcsMulticaster.multicastEvent(defaultEvent,AgvActionEventType.PASS);
//                break;
//            case LIFT_REQUEST:
//                wcsMulticaster.multicastEvent(defaultEvent,AgvActionEventType.LIFT_REQUEST);
//                break;
//            case PUT:
//                wcsMulticaster.multicastEvent(defaultEvent,AgvActionEventType.PUT);
//                break;
//        }
//
//    }
//
//
//    private void updateMissionInfo(TUSKFeedBackEvent feedBackEvent){
//        AgvMission agvMission = feedBackEvent.getAgvMission();
//        AgvMissionDetail agvMissionDetail = feedBackEvent.getAgvMissionDetail();
//        TUSKFeedBackTask tuskFeedBackTask = feedBackEvent.getTuskFeedBackTask();
//
//        AgvTaskEventType eventType = null;
//
//        if (agvMissionDetail.getTaskIndex() == 1) {
//            eventType = AgvTaskEventType.START;
//        } else if (agvMission.getTotalActionNum().equals(agvMissionDetail.getTaskIndex()) ) {
//            eventType = AgvTaskEventType.FINISH;
//        }else {
//            eventType = AgvTaskEventType.PROCESSING;
//        }
//
//        DefaultEvent defaultEvent = DefaultEvent.create(feedBackEvent);
//        wcsMulticaster.multicastEvent(defaultEvent,eventType);
//    }
//
//
//    private void updateMissionInfoasf(AgvMission agvMission, AgvMissionDetail agvMissionDetail, String agvId) {
////        agvMissionDetail.setMarkTime(LocalDateTime.now());
////        agvMissionDetail.setIsComplete(1);
////        agvMissionDetailDao.updateMarkTimeAndIsCompleteById(agvMissionDetail);
////
////        if (agvMissionDetail.getTaskIndex() == 1) {
////            agvMission.setStartTime(LocalDateTime.now());
////            agvMission.setAgvId(agvId);
////            agvMissionDao.updateStartTimeAndAgvIdById(agvMission);
////        }
////
////        agvMission.setCompleteActionNum(agvMissionDetail.getTaskIndex());
////        agvMissionDao.updateCompleteActionNumById(agvMission);
//
//
//    }
//
//}
